/*******************************************************************************
 * Copyright (c) 2008 Sylvain Sicard.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Sylvain Sicard - initial API and implementation
 ******************************************************************************/
package fr.jade.service.fm.deployment;

import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.NoSuchInterfaceException;

import fr.jade.base.JadeBaseObject;
import fr.jade.fraclite.api.control.SuperControllerNotifier;
import fr.jade.reflex.util.Reflex;
import fr.jade.util.FractalUtil;

public class CleanChildTask extends JadeBaseObject implements DeploymentTask {

  protected Component father;
  protected Component child;
  
  public CleanChildTask(Component father, Component child){
    this.father=father;
    this.child=child;
  }
  
  public void execute() throws DeploymentException {
    log("execute :" +toString());
    
    try {
      SuperControllerNotifier scn = (SuperControllerNotifier)FractalUtil.getOptSuperController(child);
      scn.removedFromFc(father);
      
      scn = (SuperControllerNotifier)FractalUtil.getOptSuperController(Reflex.getDualComponent(child));
      scn.removedFromFc(Reflex.getDualComponent(father));
      
    } catch (NoSuchInterfaceException e) {
      throw new DeploymentException("can't remove father in child", e);
    }
  }
  
  public String getLevelName(){
    return "cleanContent";
  }
  
  public String toString(){
    return "CleanChildTask[father:"+father+" - child:"+child+"]";
  }

}
